﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <h1>闭包</h1>
</body>
</html>
<script type="text/javascript">
    function obj () {
        var age = 1;

        var GetName = function () {
            return age;
        }

        return GetName();
    }

    var age = 2;
    var a = obj();
    //alert(a);

    var name = "Window";
    var object = {
        name: "mine",
        getName: function () {
            return function () {
                return this.name;
            }
        }
    };

    //alert(object.getName()())

    function F1() {
        var a = 1;

        F2 = function () {
            a++;
            return a;
        }

        return F2;
    }

    var f = F1();
    //alert(f());
    //alert(F2());
    //alert(f());

    function c() {
        this.name = "c1";
        function d() {
            var name = "d1";
            alert(name + this.name);
        }
        return d;
    }

    c()();
</script>
